# 测试构建配置

# 查找 Python 测试框架（优先使用项目内 venv 的 Python）
pytest = find_program('pytest', required: false)
use_python_module = false

# 优先使用项目内 venv 的 python 来运行 "-m pytest"
venv_py_path = join_paths(meson.project_source_root(), 'venv', 'bin', 'python')
venv_py = find_program(venv_py_path, required: false)

if venv_py.found()
    pytest = venv_py
    use_python_module = true
else
    if not pytest.found()
        python3 = find_program('python3', required: false)
        if python3.found()
            pytest = python3
            use_python_module = true
        endif
    endif
endif

# 构建测试
if pytest.found() and build_tests
    # 准备测试参数
    test_args = ['-v', '--tb=short', '.']

    if use_python_module
        test_args = ['-m', 'pytest'] + test_args
    endif

    test(
        'mcpy_python_tests',
        pytest,
        args: test_args,
        env: [
            'PYTHONPATH=' + meson.current_source_dir() / '..',
        ],
        workdir: meson.current_source_dir(),
    )
endif